When you ran the program you should have got a screen full of 'n' characters. If you look at the message array you will see that this is the first character in it. This means that our loop is "stuck" at the first character. If you look at the code which prints out the message you will see that we are incrementing pos to move us down the array. This code is missing from the first while loop, and so we get stuck at the 'n'. We can fix this by adding an increment into the while loop. If you do this you will find that your program will now print out slightly more sensible results:
no*yes
It looks as if the program is now finding something and printing out the result. It moves past no
, finds the *
and then prints yes
. We can therefore take out the #define
for DEBUG
and re-run the program.
Try this and see what happens.
void show_message(
unsigned char number)
{
int pos = 0 ;
/* find the start of message */
while ( number > 0 )
{
#ifdef DEBUG
lcd_print_ch ( messages [pos] ) ;
#endif
if ( messages [pos] == '*' )
{
number = number - 1 ;
}
pos = pos + 1 ;
}
/* print the message */
while ( messages [pos] != '*' )
{
lcd_print_ch ( messages[pos]);
pos = pos + 1 ;
}
}